package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketOrderGoods;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.bean.wubang.bo.OrderCommentBO;
import com.cskaoyan.bean.wubang.bo.OrderSubmitBO;
import com.cskaoyan.bean.wubang.vo.OrderSubmitVO;
import com.cskaoyan.bean.wubang.vo.OrderWxDetailVO;
import com.cskaoyan.bean.wubang.vo.OrderWxListVO;
import com.cskaoyan.service.OrderWxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Map;

/**
 * @auther: wubang
 * @description:
 * @date: 2022-06-29 10:36
 */

@RestController
@RequestMapping("wx/order")
public class OrderWxController {

    @Autowired
    OrderWxService orderWxService;

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, Integer showType) {
        CommonData<OrderWxListVO> orders = orderWxService.selectOrderList(baseParam, showType);
        return BaseRespVo.ok(orders);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        OrderWxDetailVO orderDetail = orderWxService.selectOrderDetail(orderId);
        return BaseRespVo.ok(orderDetail);
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderWxService.updateOrderRefund(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderWxService.deleteOrder(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderWxService.confirmOrder(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderWxService.cancelOrder(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId, Integer goodsId) {
        MarketOrderGoods marketOrderGoods = orderWxService.selectOrderGoods(orderId, goodsId);
        return BaseRespVo.ok(marketOrderGoods);
    }

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody OrderCommentBO OrderCommentBO) {
        orderWxService.insertComment(OrderCommentBO);
        return BaseRespVo.ok();
    }

    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody OrderSubmitBO orderSubmitBO) {
        OrderSubmitVO orderSubmitVO = orderWxService.insertOrder(orderSubmitBO);
        return BaseRespVo.ok(orderSubmitVO);
    }

    @PostMapping("prepay")
    public BaseRespVo prepay(){
        return BaseRespVo.ok();
    }
}
